<template>
  <a-card :bordered="false">

    <!-- 抽屉 -->
    <a-drawer
      title="字典列表"
      :width="screenWidth"
      @close="onClose"
      :visible="visible"
    >
      <!-- 抽屉内容的border -->
      <div
        :style="{
          padding:'10px',
          border: '1px solid #e9e9e9',
          background: '#fff',
        }">


        <div>
          <a-table
            ref="table"
            rowKey="id"
            size="middle"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            @change="handleTableChange"
          >


          </a-table>
        </div>
      </div>
    </a-drawer>
    <dict-item-modal ref="modalForm" @ok="modalFormOk"></dict-item-modal> <!-- 字典数据 -->
  </a-card>
</template>

<script>
  import DictItemModal from './modules/DictItemModal'
  import AkfhListMixin from '../../mixin/AkfhListMixin'
  import AkDictSelectTag from '../../components/akfh/AkDictSelectTag'
  import {sysDictUrl} from '../../api/url'

  export default {
    name: "DictItemList",
    mixins: [AkfhListMixin],
    components: {AkDictSelectTag, DictItemModal},
    data() {
      return {
        labelCol: {
          xs: {span: 24},
          sm: {span: 3}
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16}
        },
        columns: [
          {
            title: '名称',
            align: "center",
            dataIndex: 'text',
          },
          {
            title: '数据值',
            align: "center",
            dataIndex: 'value',
          },
        ],
        queryParam: {
          dictId: {
            column: "sysDictEntity.id",
            type:'eq',
            value:''
          },
          itemText: {
            column: "itemText",
            type:'like',
            value:''
          },

        },
        title: "操作",
        visible: false,
        screenWidth: 800,
        dictId: "",
        url: {
          list: sysDictUrl.itemList,
          delete: sysDictUrl.itemDelete,
          deleteBatch: sysDictUrl.itemDeleteBatch
        },
      }
    },
    created() {
      // 当页面初始化时,根据屏幕大小来给抽屉设置宽度
      this.resetScreenSize();
    },
    methods: {

      edit(record) {
        this.dataSource = record.itemModelDTOList;
        this.visible = true;

      },

      handleEdit(record){
        record.dictId = this.dictId;
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "编辑";
      },

      beforeLoadData(){
        return false;
      },
      // 添加字典数据
      handleAdd() {
        this.$refs.modalForm.add(this.dictId);
        this.$refs.modalForm.title = "新增";
      },
      onClose() {
        this.visible = false
        this.dataSource = [];
      },
      // 抽屉的宽度随着屏幕大小来改变
      resetScreenSize() {
        let screenWidth = document.body.clientWidth;
        if (screenWidth < 800) {
          this.screenWidth = screenWidth;
        } else {
          this.screenWidth = 800;
        }
      },
    }
  }
</script>
<style scoped>
</style>